package pers.whj.net.local.task;

import java.util.ArrayList;
import java.util.List;

public class FileInfoTask extends Task {
    public static final int GET_REMOTE_FILE_INFO = 201;
    public static final int DELETE_REMOTE_FILE = 202;
    public static final int RENAME_REMOTE_FILE = 203;
    public static final int CREATE_REMOTE_FILE = 204;

    private String mRemoteFilePath;
    private String mNewRemoteFilePath;
    private FileInfo mFileInfo;
    private List<CreationInfo> mCreationInfoList;

    public FileInfoTask(int type) {
        super(type);
    }

    public FileInfoTask(int type, String name, int priority) {
        super(type, name, priority);
    }

    @Override
    public void init() {
        super.init();
        mRemoteFilePath = "";
        if (getType() == CREATE_REMOTE_FILE) {
            mCreationInfoList = new ArrayList<>();
        }
    }

    public String getRemoteFilePath() {
        return mRemoteFilePath;
    }

    public void setRemoteFilePath(String remoteFilePath) {
        if (remoteFilePath != null) {
            mRemoteFilePath = remoteFilePath;
        }
    }

    public String getNewRemoteFilePath() {
        return mNewRemoteFilePath;
    }

    public void setNewRemoteFilePath(String newRemoteFilePath) {
        if (newRemoteFilePath != null) {
            mNewRemoteFilePath = newRemoteFilePath;
        }
    }

    public FileInfo getFileInfo() {
        return mFileInfo;
    }

    public void setFileInfo(FileInfo fileInfo) {
        mFileInfo = fileInfo;
    }

    public void addCreationInfo(CreationInfo creationInfo) {
        if (creationInfo != null && mCreationInfoList != null) {
            mCreationInfoList.add(creationInfo);
        }
    }

    public List<CreationInfo> getCreationInfoList() {
        return mCreationInfoList;
    }

    public static class CreationInfo {
        private String mFilePath;
        private boolean mIsDirectory;
        private boolean mSuccess;

        public CreationInfo(String filePath) {
            this(filePath, true);
        }

        public CreationInfo(String filePath, boolean isDirectory) {
            mFilePath = filePath;
            mIsDirectory = isDirectory;
            mSuccess = false;
        }

        public String getFilePath() {
            return mFilePath;
        }

        public void setFilePath(String filePath) {
            mFilePath = filePath;
        }

        public boolean isDirectory() {
            return mIsDirectory;
        }

        public void setIsDirectory(boolean directory) {
            mIsDirectory = directory;
        }

        public void setSuccess(boolean success) {
            mSuccess = success;
        }

        public boolean isSuccess() {
            return mSuccess;
        }

        public boolean isValidFilePath() {
            return mFilePath != null && mFilePath.length() > 0;
        }
    }
}